import { goodsCodeRend, goodsNameRend } from "@/utils/tableColumns";

export function useColumns() {
  const getVarianceNum = row => {
    let count = Number(row.actualNum || 0) - Number(row.inventoryNum || 0);
    return String(count);
  };

  // 库存盘点
  const kcpdColumns: TableColumnList = [
    {
      label: "商品名称/规格名称",
      prop: "businessDate",
      minWidth: 180,
      cellRenderer: goodsNameRend
    },
    {
      label: "商品编码/规格编码",
      prop: "atCount",
      minWidth: 180,
      cellRenderer: goodsCodeRend
    },
    {
      label: "商品条码",
      prop: "barCode",
      minWidth: 120,
      formatter: ({ barCode }) => barCode || "--"
    },
    {
      label: "ERP库存",
      prop: "inventoryNum",
      minWidth: 110
    },
    {
      label: "实际库存",
      prop: "actualNum",
      minWidth: 130,
      cellRenderer: ({ row }) => (
        <el-input-number
          min={0}
          step={1}
          step-strictly
          v-model={row.actualNum}
          placeholder="请输入"
          style="width: 100%"
        />
      )
    },
    {
      label: "差异数量",
      prop: "varianceNum",
      minWidth: 110,
      formatter: row => getVarianceNum(row)
    },
    {
      label: "操作",
      minWidth: 70,
      slot: "operation"
    }
  ];

  return {
    kcpdColumns
  };
}
